home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / MLCG.cc,v < prev    next >
Text File  |  1989-02-20  |  2KB  |  134 lines

  1. head     3.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @@;
  7.  
  8.  
  9. 3.2
  10. date     89.02.20.15.36.02;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.1;
  13.  
  14. 3.1
  15. date     88.12.20.13.48.59;  author grunwald;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.09.18.16.42.26;  author grunwald;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 3.2
  30. log
  31. @Start using Gnu library heaps for schedulers
  32. @
  33. text
  34. @#include "MLCG.h"
  35. //
  36. //    SEED_TABLE_SIZE must be a power of 2
  37. //
  38.  
  39.  
  40. #define SEED_TABLE_SIZE 32
  41.  
  42. static long seedTable[SEED_TABLE_SIZE] = {
  43. 0xbdcc47e5, 0x54aea45d, 0xec0df859, 0xda84637b,
  44. 0xc8c6cb4f, 0x35574b01, 0x28260b7d, 0x0d07fdbf,
  45. 0x9faaeeb0, 0x613dd169, 0x5ce2d818, 0x85b9e706,
  46. 0xab2469db, 0xda02b0dc, 0x45c60d6e, 0xffe49d10,
  47. 0x7224fea3, 0xf9684fc9, 0xfc7ee074, 0x326ce92a,
  48. 0x366d13b5, 0x17aaa731, 0xeb83a675, 0x7781cb32,
  49. 0x4ec7c92d, 0x7f187521, 0x2cf346b4, 0xad13310f,
  50. 0xb89cff2b, 0x12164de1, 0xa865168d, 0x32b56cdf
  51. };
  52.  
  53. MLCG::MLCG(long seed1, long seed2)
  54. {
  55.     initialSeedOne = seed1;
  56.     initialSeedTwo = seed2;
  57.     reset();
  58. }
  59.  
  60. void
  61. MLCG::reset()
  62. {
  63.     long seed1 = initialSeedOne;
  64.     long seed2 = initialSeedTwo;
  65.  
  66.     //
  67.     //    Most people pick stupid seed numbers that do not have enough
  68.     //    bits. In this case, if they pick a small seed number, we
  69.     //    map that to a specific seed.
  70.     //
  71.     if (seed1 < 0) {
  72.     seed1 = (seed1 + 2147483561);
  73.     seed1 = (seed1 < 0) ? -seed1 : seed1;
  74.     }
  75.  
  76.     if (seed2 < 0) {
  77.     seed2 = (seed2 + 2147483561);
  78.     seed2 = (seed2 < 0) ? -seed2 : seed2;
  79.     }
  80.  
  81.     if (seed1 > -1 && seed1 < SEED_TABLE_SIZE) {
  82.     seedOne = seedTable[seed1];
  83.     } else {
  84.     seedOne = seed1 ^ seedTable[seed1 & (SEED_TABLE_SIZE-1)];
  85.     }
  86.  
  87.     if (seed2 > -1 && seed2 < SEED_TABLE_SIZE) {
  88.     seedTwo = seedTable[seed2];
  89.     } else {
  90.     seedTwo = seed2 ^ seedTable[ seed2 & (SEED_TABLE_SIZE-1) ];
  91.     }
  92.     seedOne = (seedOne % 2147483561) + 1;
  93.     seedTwo = (seedTwo % 2147483397) + 1;
  94. }
  95.  
  96. unsigned long MLCG::asLong()
  97. {
  98.     long k = seedOne % 53668;
  99.  
  100.     seedOne = 40014 * (seedOne-k * 53668) - k * 12211;
  101.     if (seedOne < 0) {
  102.     seedOne += 2147483563;
  103.     }
  104.  
  105.     k = seedTwo % 52774;
  106.     seedTwo = 40692 * (seedTwo - k * 52774) - k * 3791;
  107.     if (seedTwo < 0) {
  108.     seedTwo += 2147483399;
  109.     }
  110.  
  111.     long z = seedOne - seedTwo;
  112.     if (z < 1) {
  113.     z += 2147483562;
  114.     }
  115.     return( (unsigned long) z);
  116. }
  117. @
  118.  
  119.  
  120. 3.1
  121. log
  122. @Steay version
  123. @
  124. text
  125. @@
  126.  
  127.  
  128. 1.1
  129. log
  130. @Initial revision
  131. @
  132. text
  133. @@
  134.